//
//  YCOrderDetailViewController.m
//  YCVillageDoctor
//
//  Created by Mac on 2017/6/7.
//  Copyright © 2017年 zhangxiaoliang. All rights reserved.
//

#import "YCOrderDetailViewController.h"
#import "YCOrderDetailModel.h"
#import "YCReadingViewController.h"
#define padding 10

@interface YCOrderDetailViewController ()
@property(nonatomic,weak)UILabel *siteLabel;
@property(nonatomic,weak)UIView *lineView1;
@property(nonatomic,weak)UILabel *productLabel;
@property(nonatomic,weak)UIView *lineView2;
@property(nonatomic,weak)UILabel *payTimeLabel;
@property(nonatomic,weak)UIView *lineView3;
@property(nonatomic,weak)UILabel *tagLabel;
@property(nonatomic,weak)UIView *backView1;
@property(nonatomic,weak)UILabel *startTimLabel;
@property(nonatomic,weak)UIView *backView2;
@property(nonatomic,weak)UILabel *endTimLabel;
@end

@implementation YCOrderDetailViewController{
    BOOL _isChecked;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"订单详情";
    [self setUpSubViews];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self loadData];
}
-(void)loadData {

    self.siteLabel.text = [NSString stringWithFormat:@"站点名称: %@",judgeString(self.model.hosName)];
    self.productLabel.text = [NSString stringWithFormat:@"产品名称: %@元套餐", judgeString(self.model.payMoney)];
    
    NSString *atartStr = self.model.checkDate;
    
    NSString *startStr = @"";
    
    NSString *endStr = @"";
    
    if (atartStr!=nil) {
        
        NSDate *date = [NSDate dateOfStringWithFormat:YcFormatterStyleYYYYMMddHHmmss WithDateString:atartStr];
        
        startStr = [date stringOfDateWithFormat:YcFormatterStyleYMdC];
        
        NSInteger i = 0;
        //计算n天之后的时间
        if ([self.model.payMoney isEqualToString:@"150"]) {
            i = 30;
        }else{
            i = 90;
        }
        NSDate *endDate = [date yc_dateByAddingDays:i];
        
        endStr = [endDate stringOfDateWithFormat:YcFormatterStyleYMdC];
    }

    self.payTimeLabel.text = [NSString stringWithFormat:@"支付时间: %@",(_isChecked?@"待审核":judgeString(self.model.payTime))];

}
-(void)setUpSubViews {
    
     _isChecked = [self.model.checkFlag isEqualToString:@"待审核"];
    
    UILabel *siteLabel = [[UILabel alloc]init];
    
    self.siteLabel = siteLabel;
    
    siteLabel.textColor = [UIColor grayColor];
    
    siteLabel.font = [UIFont systemFontOfSize:15];
    
    UIView *lineView1 = [[UIView alloc]init];
    
    self.lineView1 = lineView1;
    
    lineView1.backgroundColor = [UIColor colorWithCommonType:CommonColorSubFCGray];
    
    UILabel *productLabel = [[UILabel alloc]init];
    
    self.productLabel = productLabel;
    
    productLabel.textColor = [UIColor grayColor];
    
    productLabel.font = [UIFont systemFontOfSize:15];
    
    UIView *lineView2 = [[UIView alloc]init];
    
    self.lineView2 = lineView2;
    
    lineView2.backgroundColor = [UIColor colorWithCommonType:CommonColorSubFCGray];
    
    UILabel *payTimeLabel = [[UILabel alloc]init];
    
    self.payTimeLabel = payTimeLabel;
    
    payTimeLabel.textColor = [UIColor grayColor];
    
    payTimeLabel.font = [UIFont systemFontOfSize:15];
    
    UIView *lineView3 = [[UIView alloc]init];
    
    self.lineView3 = lineView3;
    
    lineView3.backgroundColor = [UIColor colorWithCommonType:CommonColorSubFCGray];
    
    [self.view addSubview:siteLabel];
    
    UIButton *bugBtn = [[UIButton alloc]init];
    
    bugBtn.backgroundColor = [UIColor colorWithCommonType:CommonColorBlue];
    
    [bugBtn setTitle:@"再次购买" forState:UIControlStateNormal];
    
    [bugBtn addTarget:self action:@selector(submitClick:) forControlEvents:UIControlEventTouchUpInside];
    
    bugBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    
    bugBtn.layer.cornerRadius = 3;
    
    bugBtn.layer.masksToBounds = YES;
    
    //添加Ui约束
    [siteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(padding);
        make.left.mas_equalTo(padding);
    }];
    
    [self.view addSubview:lineView1];
    
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(siteLabel.mas_bottom).offset(padding);
        
        make.left.equalTo(self.view).offset(padding);
        
        make.right.mas_equalTo(self.view);
        
        make.height.mas_equalTo(1);
    }];
    
    [self.view addSubview:productLabel];
    
    [productLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(lineView1.mas_bottom).offset(padding);
        
        make.left.mas_equalTo(padding);
    }];
    
    [self.view addSubview:lineView2];
    
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(productLabel.mas_bottom).offset(padding);
        
        make.left.equalTo(self.view).offset(padding);
        
        make.right.mas_equalTo(self.view);
        
        make.height.mas_equalTo(1);
    }];
    
    [self.view addSubview:payTimeLabel];
    
    [payTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(lineView2.mas_bottom).offset(padding);
        
        make.left.mas_equalTo(padding);
    }];
    
    [self.view addSubview:lineView3];
    
    [lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(payTimeLabel.mas_bottom).offset(padding);
        
        make.left.equalTo(self.view).offset(padding);
        
        make.right.mas_equalTo(self.view);
        
        make.height.mas_equalTo(1);
    }];
    
    [self.view addSubview:bugBtn];
    
    [bugBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(10);
        
        make.right.mas_equalTo(self.view).offset(-10);
        
        make.height.mas_equalTo(44);
        
        make.bottom.mas_equalTo(self.view).offset(-49-20);
        
    }];
    
    //设置假数据
    siteLabel.text = @"站点名称:";
    productLabel.text = @"产品名称:";

}

#pragma mark - 提交
-(void)submitClick:(UIButton*)btn{
    
    YCReadingViewController *readingrVc = [[YCReadingViewController alloc] init];
    
    [self.navigationController pushViewController:readingrVc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
